{extend name='public/layout' /}

{block name="assign"}
{block name="assign"}
{if isset($info)}
{assign name="page_title" value="编辑文章" /}
{else/}
{assign name="page_title" value="新增文章" /}
{/if}
{/block}

{block name='importCss'}
<link rel="stylesheet" href="__STATIC__/vendor/layui-modules/formSelects/formSelects-v4.css">
{/block}

{block name='body'}
<div class="layui-card">
	<div class="layui-card-body">
		<form method="post" action="{:url()}" class="layui-form layui-form-edit">
			<input type="hidden" name="id" value="{$info.id|default=0}">
			<input type="hidden" name="http_referer" value="{$Request.server.HTTP_REFERER|default=''}"/>

			<div class="layui-form-item">
				<label class="layui-form-label" for="title">标题<i class="required"></i></label>
				<div class="layui-input-block">
					<input type="text" id="title" name="title" value="{$info.title|default=''}" placeholder="请输入标题" class="layui-input" lay-verify="required" autocomplete="on"/>
					<div class="layui-form-mid"></div>
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label" for="category_id">分类<i class="required"></i></label>
				<div class="layui-input-inline">
					<select id="category_id" name="category_id" lay-verify="required">
						<option value="">请选择分类</option>
						{volist name='categories' id='vo'}
						<option value="{$vo.id}">{$vo.title|raw}</option>
						{/volist}
					</select>
					<div class="layui-form-mid"></div>
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">封面<i class="required"></i></label>
				<div class="layui-input-inline">
					<div data-img-uploader="{name:'cover'}" data-path="{$info.cover|default=''}"></div>
				</div>
			</div>

<!--			<div class="layui-form-item">-->
<!--				<label class="layui-form-label" for="description">简介<i class="required"></i></label>-->
<!--				<div class="layui-input-block">-->
<!--					<textarea id="description" name="description" class="layui-textarea" rows="3" lay-verify="required">{$info.description|default=''}</textarea>-->
<!--					<div class="layui-form-mid"></div>-->
<!--				</div>-->
<!--			</div>-->

			<div class="layui-form-item">
				<label class="layui-form-label" for="content">正文<i class="required"></i></label>
				<div class="layui-input-block">
					<textarea id="content" name="content" class="layui-textarea" rows="3" lay-verify="required" data-editor>{$info.content|default=''}</textarea>
					<div class="layui-form-mid"></div>
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label" for="status">状态</label>
				<div class="layui-input-inline">
					<input type="hidden" name="status" value="0"/>
					<input type="checkbox" id="status" name="status" value="1" lay-filter="status" lay-skin="switch" lay-text="启用|禁用"/>
					<div class="layui-form-mid"></div>
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label" for="view_count">浏览量</label>
				<div class="layui-input-inline">
					<input type="number" id="view_count" name="view_count" class="layui-input" placeholder="当前浏览量{$info.view_count|default=0}" lay-verify="required"/>
					<div class="layui-form-mid">不填保持最新</div>
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label" for="original_url">公众号链接</label>
				<div class="layui-input-block">
					<input type="text" id="original_url" name="original_url" value="{$info.original_url|default=''}" placeholder="请输入公众号链接" class="layui-input"/>
					<div class="layui-form-mid"></div>
				</div>
			</div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<button type="submit" class="layui-btn layui-btn-danger" data-ajax-post="{target:'.layui-form'}">
						<i class="fa fa-save"></i> 保存
					</button>
					<a href="javascript:history.back();" class="layui-btn layui-btn-primary">取消 </a>
				</div>
			</div>

		</form>
	</div>
</div>
{/block}

{block name='scriptVar'}
xin.setValue('#category_id',{$info.category_id|default=''});
xin.setValue('badge_id_list[]',{:json_encode(isset($info)?$info.badge_id_list:[])});
xin.setChecked('#status',{$info.status|default='1'});
{/block}

{block name='foot'}
<script>
$(function() {
	$('#original_url').change(function(e) {
		var url = $(this).val();
		if (!url) return;

		// 抓取信息
		var handler = function() {
			xin.request.get("{:url('/article/collect')}", {
				url: url
			}, {
				tipsSuccessMsg: false
			}).then(function(res) {
				console.log(res);
				$('#title').val(res.data.title);
				$('#content')[0].editor.setValue(res.data.content);
			});
		};

		xin.showModal({
			title: '温馨提示',
			content: '是否抓取文章信息？',
			showCancel: true,
		}).then(function(res) {
			if (res.cancel) return;

			handler();
		});
	});
});

layui.use(['formSelects']);
</script>
{/block}
